package com.panda.web.controller.commons;

import java.util.List;
import java.util.Arrays;
import com.panda.common.core.domain.R;
import com.panda.web.domain.vo.EditionVO;
import com.panda.web.entity.commons.SpecialEdition;
import com.panda.web.mapper.commons.SpecialEditionMapper;
import com.panda.web.service.commons.ISpecialEditionService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.panda.web.utils.pageutils.PageResult;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;


/**
 * 专业分类Controller
 *
 * @author cpanda
 * @date 2025-03-05
 */
@CrossOrigin
@RestController
@RequestMapping("/web/edition")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SpecialEditionController extends BaseController {
    private final ISpecialEditionService editionService;

    /**
     * 查询专业分类列表
     */
    @GetMapping("/list")
    public PageResult<SpecialEdition> List(SpecialEdition edition,
                                           @RequestParam("pageNum") Integer pageNum,
                                           @RequestParam("pageSize") Integer pageSize) {
        //返回分页信息
        PageResult<SpecialEdition> voList = editionService.PageList(edition,pageNum,pageSize);
        return voList;
    }


    /**
     * 查询专业分类列表 无分页
     */
    @GetMapping("/choiceList")
    public R choiceList(SpecialEdition edition) {
        List<SpecialEdition> voList = editionService.choiceList(edition);
        return R.ok(voList,"ok");
    }
    /**
     * 多级分类搜索查询
     */
    @GetMapping("/specialTree")
    public R getSpecialTree(SpecialEdition edition){
        List<EditionVO> vo  = editionService.getSpecialTree(edition);
        return R.ok(vo,"ok");
    }
    /**
     * 获取专业分类详细信息
     */
    @GetMapping(value = "/{specialId}")
    public AjaxResult getInfo(@PathVariable("specialId") Long specialId) {
        return AjaxResult.success(editionService.selectById(specialId));
    }

    /**
     * 新增专业分类
     */
    @Log(title = "专业分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecialEdition edition) {
        return toAjax(editionService.insert(edition));
    }

    /**
     * 修改专业分类
     */
    @Log(title = "专业分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecialEdition edition) {
        return toAjax(editionService.updateEditionById(edition));
    }

    /**
     * 删除专业分类
     */
    @Log(title = "专业分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{specialIds}")
    public AjaxResult remove(@PathVariable Long[] specialIds) {
        return toAjax(editionService.removeByEditionIds(Arrays.asList(specialIds)));
    }


}
